package tal.gateway.gatewaydemo.filter;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Date;

@Component
public class LogGatewayFilter implements GlobalFilter, Ordered {
    private static Logger log = LoggerFactory.getLogger(LogGatewayFilter.class);
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("enter LogGatewayFilter....." +  new Date());
        /*String uname = exchange.getRequest().getQueryParams().getFirst("uname");//获取参数
        if(uname == null){
            log.info("......用户名为null,非法用户.......");
            exchange.getResponse().setStatusCode(HttpStatus.NOT_ACCEPTABLE);
            return exchange.getResponse().setComplete();
        }*/
        return chain.filter(exchange);
    }

    //加载过滤器的顺序
    @Override
    public int getOrder() {
        return 0;
    }
}
